define(['angular', 'app.directives','directives/common/ueditor2','directives/common/laydate','services/xdd/xdd_service','controllers/xdd/xdd','filters/common/base'], function (angular, directives) {
    'use strict';

    /**
     *
     */
    directives.directive("evaluateManager", ['$stateParams','CurrentUser', function ($stateParams,CurrentUser) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/evaluate_manager.html",
            link: function ($scope) {

            }
        }
    }]);
    /**
     *
     */
    directives.directive("evaluateDetail", ['$stateParams','CurrentUser', function ($stateParams,CurrentUser) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/evaluate_detail.html",
            link: function ($scope) {

            }
        }
    }]);
    /**
     * 商品列表页面
     */
    directives.directive("goodsList", ['$q','$location','$stateParams','CurrentUser','$uibModal','xddService', function ($q,$location,$stateParams,CurrentUser,$uibModal,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: function () {
                return "/app/partial/xdd/goods_list.html";
            },
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.goodsParam={};
                $scope.currentPage=1;
                $scope.itemsPerPage=10;

                xddService.getTypeOne(function(data){
                    $scope.typeOneList=data.data;
                },function(data){
                    alert("获取数据失败");
                });

                var getSecondType=function(pId,level){
                    xddService.getSecondType(pId,level,function (data) {
                        if(level=="2"){
                            $scope.gstyleList=data.data.styleList;
                        }else{
                            $scope.typeList=data.data.typeList;
                        }
                    },function () {

                    });
                }
                $scope.getChildType=function(level){
                    var pId="";
                    if(level=="2"){
                        $scope.pxList=[];
                        pId=$scope.goodsParam.type;
                        $scope.goodsParam.gstyle="";
                        $scope.goodsParam.px="";
                    }else{
                        pId=$scope.goodsParam.typeOne;
                        $scope.gstyleList=[];
                        $scope.pxList=[];
                        $scope.goodsParam.type="";
                        $scope.goodsParam.gstyle="";
                        $scope.goodsParam.px="";
                    }
                    getSecondType(pId,level);
                    ///根据材质获取当日价格
                }
                $scope.getPxByStyle=function(){
                    $scope.goodsParam.px="";
                    xddService.getPxByStyle($scope.goodsParam.gstyle,function(data){
                        $scope.pxList=data.data;
                    },error)
                }



                var getList = function () {
                    xddService.getGoodsList($scope.currentPage, $scope.itemsPerPage, $scope.goodsParam, function (data) {
                        $scope.goodsList = data.data.list;
                        if( $scope.currentPage==1){
                            $scope.totalItems = data.data.count;
                        }
                    }, error);
                };
                getList();
                $scope.pageChanged=function(){
                    getList();
                };
                $scope.searchGoodsList=function(){
                    $scope.currentPage=1;
                    getList();
                };
                $scope.updateStatus=function(goods,status){

                    if(goods.checkStatus!="1"){
                        alert("尚未审核不允许操作");
                        return false;
                    }
                    xddService.updateStatus(goods.id,status,function(){
                        if(status==0){
                            alert("下架成功");
                        }else{
                            alert("上架成功");
                        }
                        getList();
                    },function () {
                        alert("操作失败，请重试！")
                    });
                };

                $scope.deleteGoods=function (goodsId) {
                    xddService.deleteGoods(goodsId,function(){
                        alert("删除成功！");
                        getList();
                    },function () {
                        alert("删除失败！");
                    })
                };

                $scope.reviewGoods=function (goods) {
                   var checkGoods=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/goodsReview.html',
                        controller: "reviewGoodsController",
                        resolve: {
                            model:{goods:goods}
                        }
                    });
                    checkGoods.result.then(function () {
                        getList();
                    });
                }

                var idArr=function(){
                    var listId=[];
                    //获取复选框id
                    var menu = $('input[name="goodsId"]:checked ');
                    angular.forEach(menu, function (data) {
                        listId.push(data.value);
                    });
                    return listId;
                };

                //复制
                $scope.copyGoods=function(){
                    var ids=idArr();
                    if(ids.length==0){
                        layer.alert("请选择要复制产品");
                    }else{
                        xddService.copyGoodsByIds(ids,function(data){
                            layer.alert("复制成功");
                            getList();
                        },error);
                    }
                };

                //批量上架
                $scope.grounding=function(status){
                    var ids=idArr();
                    if(ids.length==0){
                        layer.alert("请选择要上架的产品");
                    }else {
                        var flag=true;
                        angular.forEach(ids,function(id){
                            for(var i=0;i<$scope.goodsList.length;i++){
                                console.info($scope.goodsList[i]);
                                if(id==$scope.goodsList[i].id){
                                   if($scope.goodsList[i].checkStatus!=1){
                                       flag=false;
                                   }
                                }
                            }
                        });
                        if(!flag){
                            layer.alert("所选商品存在未审核或审核未通过，不允许操作！");
                        }else{
                            xddService.grounding(ids,function(data){
                                layer.alert("批量上架成功");
                                getList();
                            },error);
                        }
                    };
                };

                //批量下架
                $scope.undercarriage=function(){
                    var ids=idArr();
                    if(ids.length==0){
                        layer.alert("请选择要下架的产品");
                    }else {
                        xddService.undercarriage(ids,function(data){
                            layer.alert("批量下架成功");
                            getList();
                        },error);
                    };
                };

                //批量审核
                $scope.review=function(){
                    var ids=idArr();
                    if(ids.length==0){
                        layer.alert("请选择要审核的产品");
                    }else {
                        xddService.review(ids,function(data){
                            layer.alert("批量审核成功");
                            getList();
                        },error);
                    };
                };

            }
        }
    }]);
    //修改商品
    directives.directive("goodsUpdate", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/goods_update.html",
            link: function ($scope) {
                $scope.currentPage=1;
                $scope.itemsPerPage=10;
                var error=function(err){
                    layer.alert(err.message);
                };

                $("#file-1").fileinput({
                    uploadUrl: '/dapi/upload/attachment', // you must set a valid URL here else you will get an error
                    allowedFileExtensions : ['jpg','jpeg', 'png','gif'],
                    overwriteInitial: false,
                    maxFileSize: 10000,
                    //allowedFileTypes: ['image', 'video', 'flash'],
                    slugCallback: function(filename) {
                        return filename.replace('(', '_').replace(']', '_');
                    }
                }).on("fileuploaded", function(event, data) {
                    if(data.response) {
                        $scope.picUrl=data.response.data;
                        //alert('处理成功');
                        var param={};
                        param.goodsId=$stateParams.id;
                        param.pic_path=data.response.data;
                        xddService.addGoodsPic(param,function () {

                        },error);

                    }
                });
                $scope.haveScond="0";
                var getTypeOne=function(){
                    xddService.getTypeOne(function (data) {
                        $scope.typeOneList=data.data;
                    },function () {

                    });
                }
                getTypeOne();

                var getSecondType=function(pId,level){
                    xddService.getSecondType(pId,level,function (data) {
                        $scope.haveScond=data.data.haveType;
                        if(level=="2"){
                            $scope.gstyleList=data.data.styleList;
                        }else{
                            $scope.typeList=data.data.typeList;
                        }
                    },function () {

                    });
                }
                $scope.getChildType=function(level){
                    var pId="";
                    if(level=="2"){
                        $scope.pxList=[];
                        pId=$scope.goods.type;
                        angular.forEach($scope.typeList,function(type){
                            if(type.id==$scope.goods.type){
                                $scope.goods.price=type.price;
                            }
                        })
                    }else{
                        pId=$scope.goods.typeOne;
                        $scope.gstyleList=[];
                        $scope.pxList=[];
                    }
                    getSecondType(pId,level);
                }
                $scope.getPxByStyle=function(){
                    xddService.getPxByStyle($scope.goods.gstyle,function(data){
                        $scope.pxList=data.data;
                    },error)
                }
                //获取商品图片
                var getPic=function(){
                    xddService.getGoodsPic($stateParams.id,function(data){
                        $scope.imgUrlList=data.data;
                    },error);
                }
                getPic();
                //获取商品信息
                xddService.getGoodsById($stateParams.id,function(data){
                    $scope.goods=data.data;
                   /* xddService.getTypeAndStyle($scope.goods.type,$scope.goods.gstyle,function(data){
                        $scope.typeList=data.data.typeList;
                        $scope.gstyleList=data.data.styleList;
                    },error)*/
                    if(data.data.type!=""&&data.data.type!=null){
                        xddService.getTypeByGoodType(data.data.type,function(data){
                            $scope.typeList=data.data.typeList;
                        },error)
                    }
                    if(data.data.gstyle!=""&&data.data.gstyle!=null){
                        xddService.getStyleByGoodStyle(data.data.gstyle,function(data){
                            $scope.gstyleList=data.data.styleList;
                        },error)
                        xddService.getPxByStyle(data.data.gstyle,function(data){
                            $scope.pxList=data.data;
                        },error)
                    }

                },error);
                //获取商品评价
                xddService.getEvaluate($stateParams.id,$scope.currentPage, $scope.itemsPerPage,function(data){
                    $scope.evaluateList=data.data.list;
                },error);
                //上传图片
                var uploadFile=function (formData) {
                    $.ajax({
                        method:'POST',
                        url:"/dapi/upload",
                        data: formData,
                        processData: false,
                        contentType : false,
                        headers: {'Content-Type':undefined},
                        transformRequest: angular.identity
                    }).success(function(data){
                        // alert("上传成功");
                        $scope.pic_path=data.data;
                        $scope.goods.iconUrl=data.data;
                        var param={};
                        param.goodsId=$stateParams.id;
                        param.pic_path=data.data;
                        xddService.updateIconUrl(param,function(data){
                            alert("修改成功");
                        },error)
                    });
                };
                var uploadFileTzs=function (formData) {
                    $.ajax({
                        method:'POST',
                        url:"/dapi/upload/zs",
                        data: formData,
                        processData: false,
                        contentType : false,
                        headers: {'Content-Type':undefined},
                        transformRequest: angular.identity
                    }).success(function(data){
                        // alert("上传成功");
                        $scope.pic_path=data.data;
                        $scope.goods.iconUrl=data.data;
                        var param={};
                        param.goodsId=$stateParams.id;
                        param.pic_path=data.data;
                        xddService.updateIconUrl(param,function(data){
                            alert("修改成功");
                        },error)
                    });
                };
                //删除商品评价
                $scope.deleteEvaluate=function(evaId){
                    xddService.deleteEvaluate(evaId,function(data){
                        alert("删除评价成功！");
                        xddService.getEvaluate($stateParams.id,$scope.currentPage, $scope.itemsPerPage,function(data){
                            $scope.evaluateList=data.data.list;
                        },error);
                    },error)
                }
                //删除商品展示图
                $scope.deleteIconUrl=function(id){
                    xddService.deleteIconUrl(id,function(data){
                        alert("删除成功！");
                        getPic();
                    },error)
                };
                //删除商品轮播图
                $scope.deletePic=function(item){
                    xddService.deletePic($stateParams.id,item.id,item.picUrl,function(data){
                        alert("删除成功！");
                        getPic();
                    },error)
                }
                $scope.uploadPic=function () {
                    var formData = new FormData();
                    var fileZs=document.querySelector('input[type="file"]').files[0];
                    if(fileZs!=null){
                        if(fileZs.size>102400){
                            alert("展示图文件不超过100K");
                            return false;
                        }
                        formData.append("file",fileZs);
                    }else{
                        alert("请选择文件");
                        return false;
                    }
                    uploadFileTzs(formData);
                }
                //获取商品规格信息
                xddService.getGoodsWeightById($stateParams.id,function(data){
                    $scope.goodsWeightList=data.data;
                },error);
                $scope.goodsWeightList=[{"minWeight":0,"maxWeight":0}];
                //提交
                $scope.submitGoods=function(){
                    $scope.goods.goodsWeightList=$scope.goodsWeightList;
                    xddService.updateGoods($scope.goods,function(data){
                        alert("修改成功");
                    },error)
                };
                $scope.addGoodsWeight=function () {
                    $scope.goodsWeightList.push({"minWeight":0,"maxWeight":0});
                }
                $scope.deleteGoodsWeight=function (index) {
                    $scope.goodsWeightList.splice(index,1);
                }
            }
        }
    }]);
    //修改商品
    directives.directive("goodsDetail", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/goods_detail.html",
            link: function ($scope) {
                $scope.currentPage=1;
                $scope.itemsPerPage=10;
                var error=function(err){
                    layer.alert(err.message);
                }
                //获取商品信息
                xddService.getGoodsById($stateParams.id,function(data){
                    $scope.goods=data.data;
                },error);
                //获取商品规格信息
                xddService.getGoodsWeightById($stateParams.id,function(data){
                    $scope.goodsWeightList=data.data;
                },error);
                //获取商品图片
                xddService.getGoodsPic($stateParams.id,function(data){
                    $scope.imgUrlList=data.data;
                },error);
                //获取商品评价
                xddService.getEvaluate($stateParams.id,$scope.currentPage, $scope.itemsPerPage,function(data){
                    $scope.evaluateList=data.data.list;
                },error);
                /*$scope.imageBroadcastFun=function(){
                    $uibModal.open({
                        animation: true,
                        size:"sm",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/images_broadcast.html',
                        controller: "imageBroadcastController",
                        resolve: {
                            model:{}
                        }
                    });
                }*/

            }

        }
    }]);
    //添加商品页面
    directives.directive("goodsAdd", ['$stateParams','xddService', function ($stateParams,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: function () {
                return "/app/partial/xdd/goods_add.html";
            },
            link: function ($scope) {
                var error=function(err){
                    alert(err.message);
                }
                $scope.haveScond="0";
                var getTypeOne=function(){
                    xddService.getTypeOne(function (data) {
                        $scope.typeOneList=data.data;
                    },function () {

                    });
                }
                getTypeOne();
                var getSecondType=function(pId,level){
                    xddService.getSecondType(pId,level,function (data) {
                        $scope.haveScond=data.data.haveType;
                        if(level=="2"){
                            $scope.gstyleList=data.data.styleList;
                        }else{
                            $scope.typeList=data.data.typeList;
                        }
                    },function () {

                    });
                }
                $scope.getChildType=function(level){
                    var pId="";
                    if(level=="2"){
                        $scope.pxList=[];
                        pId=$scope.goods.type;
                        angular.forEach($scope.typeList,function(type){
                            if(type.id==$scope.goods.type){
                                $scope.goods.price=type.price;
                            }
                        })

                    }else{
                        pId=$scope.goods.typeOne;
                        $scope.gstyleList=[];
                        $scope.pxList=[];
                    }
                    getSecondType(pId,level);
                    ///根据材质获取当日价格
                }
                $scope.getPxByStyle=function(){
                    xddService.getPxByStyle($scope.goods.gstyle,function(data){
                        $scope.pxList=data.data;
                    },error)
                }
                $scope.goodsWeightList=[{"minWeight":0,"maxWeight":0}];
                $scope.goods={};
                $scope.addGoods=function () {
                    $scope.goods.goodsWeightList=$scope.goodsWeightList;
                    xddService.addGoods($scope.goods,function () {
                        alert("添加成功")
                        $scope.submitIsClick=false;
                    },error);
                }
                $scope.addGoodsWeight=function () {
                    $scope.goodsWeightList.push({"minWeight":0,"maxWeight":0})
                }
                $scope.deleteGoodsWeight=function (index) {
                    $scope.goodsWeightList.splice(index,1);
                }
            }
        }
    }]);
    //修改旧物
    directives.directive("oldGoodsUpdate", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/oldGoods_update.html",
            link: function ($scope) {
                $("#file-1").fileinput({
                    uploadUrl: "/dapi/upload/attachment", // you must set a valid URL here else you will get an error
                    allowedFileExtensions : ['jpg','jpeg', 'png','gif'],
                    overwriteInitial: false,
                    maxFileSize: 100000,
                    slugCallback: function(filename) {
                        return filename.replace('(', '_').replace(']', '_');
                    }
                }) .on("fileuploaded", function(event, data) {
                    if(data.response) {
                        $scope.picUrl=data.response.data;
                    }
                });


                $scope.currentPage=1;
                $scope.itemsPerPage=10;
                var error=function(err){
                    layer.alert(err.message);
                }
                xddService.getGType('2',function (data) {
                    $scope.typeList=data.data;
                },function () {

                });
                //删除商品展示图
                $scope.deleteIconUrl=function(id){
                    xddService.deleteOldIconUrl(id,function(data){
                        alert("删除成功！");

                    },error)
                };
                //获取商品信息
                xddService.getOldById($stateParams.id,function(data){
                    $scope.old=data.data;
                },error);
                //提交
                $scope.submitOld=function(){
                    if($scope.picUrl!=undefined&&$scope.picUrl!=""){
                        $scope.old.iconUrl=$scope.picUrl;
                        $scope.old.ifPic=1;
                    }
                    xddService.updateOld($scope.old,function(data){
                        alert("修改成功");
                    },error)
                }
            }
        }
    }]);
    //客服列表
    directives.directive("kfryList", ['$stateParams','CurrentUser', function ($stateParams,CurrentUser) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/kfry_list.html",
            link: function ($scope) {
            }
        }
    }]);
    //客服人员的聊天列表
    directives.directive("kfryChatList", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/kfry_chat_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                var getList=function(){
                    xddService.getUserListWithMsg( $scope.currentPage,$scope.itemsPerPage,{},function(data){
                        $scope.userList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                getList();
                $scope.pageChanged=function(){
                    getList();
                };
                $scope.cleanTalkMsgFun=function(userId){
                    xddService.clearTalkMsg(userId,function(data){
                        //getList();
                        alert("已清空");
                    },error)
                }
                function getCheckBoxRes(name){
                    var rdsObj   = document.getElementsByName(name);
                    var checkVal = new Array();
                    var k        = 0;
                    for(var i = 0; i < rdsObj.length; i++){
                        if(rdsObj[i].checked){
                            checkVal[k] = rdsObj[i].value;
                            k++;
                        }
                    }
                    return checkVal;
                }
                $scope.mutCleanMsgFun=function(){
                    var userIds=getCheckBoxRes("userMsg");
                    xddService.mutClearTalkMsg(userIds,function(data){
                        alert("已清空");
                    },error)
                }
            }
        }
    }]);
    //客服人员与用户的聊天记录
    directives.directive("kfryChatUserList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/kfry_chat_user_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.userId=$stateParams.userId;
                //获取该用户与我的聊天记录
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                var getList=function(){
                    xddService.getTalkRecordWithMe($scope.userId, $scope.currentPage,  $scope.itemsPerPage,function(data){
                        $scope.talkList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error)
                }
                getList();
                $scope.pageChanged=function(){
                    getList();
                };
                //撤销聊天信息
                $scope.deleteTalkMsg=function(msgId){
                    xddService.deleteTalkMsg(msgId,function(data){
                        getList();
                    },error)
                }
                $scope.lookImage=function(yyzzUrl){
                    $uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/look_yyzz.html',
                        controller: "lookUserYyzzController",
                        resolve: {
                            model:{yyzzUrl:yyzzUrl}
                        }
                    });
                }
            }
        }
    }]);
    //协议列表
    directives.directive("agreementList", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/agreement_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                //获取协议列表数据
                xddService.getAgreemeneList(function(data){
                    $scope.agreementList=data.data;
                },error)



            }
        }
    }]);
    //协议详情
    directives.directive("agreementDetail", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/agreement_detail.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                //获取协议列表数据
                xddService.getAgreemeneDetail($stateParams.id,function(data){
                    $scope.agreement=data.data;
                },error)

                $scope.isUpdate=false;
                $scope.updateAgreement=function(){
                    $scope.isUpdate= !$scope.isUpdate;
                }
                //提交保存
                $scope.submitAgreement=function(){
                    if($scope.agreement.des!=undefined&&$scope.agreement.des.trim()!=""){
                        xddService.submitAgreement($scope.agreement,function(data){
                            alert("修改成功");
                            $scope.isUpdate=false;
                        },error)
                    }else{
                        alert("请输入协议内容");
                    }
                }

            }
        }
    }]);
    //消息群发
    directives.directive("messagegroupList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/messagegroup/messagegroup_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                $scope.searchParam={};
                var getList=function(){
                    xddService.getMessageGroupList( $scope.currentPage,$scope.itemsPerPage,$scope.searchParam,function(data){
                        $scope.messagegroupList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                getList();
                $scope.searchList=function(){
                    getList();
                }
                $scope.pageChanged=function(){
                    getList();
                };
                $scope.deleteMessagegroupFun=function(messageGroupId){
                    xddService.deleteMessagegroup(messageGroupId,function(data){
                        alert("删除成功");
                        getList();
                    },error)
                }
                $scope.detailMessagegroupFun=function(messageGroup){
                    var detailMessageGroup=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/messagegroup/messagegroup_detail.html',
                        controller: "detailMessageGroupController",
                        resolve: {
                            model:{messageGroup:messageGroup}
                        }
                    });
                }
                $scope.updateMessagegroupFun= function (messageGroup) {
                    var updateMessageGroup=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/messagegroup/messagegroup_add_update.html',
                        controller: "updateMessageGroupController",
                        resolve: {
                            model:{messageGroup:messageGroup}
                        }
                    });
                }
                $scope.addMessagegroupFun=function(){
                    var addMessageGroup=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/messagegroup/messagegroup_add_update.html',
                        controller: "addMessageGroupController",
                        resolve: {
                            model:{}
                        }
                    });
                    addMessageGroup.result.then(function () {
                        getList();
                    });
                }
            }
        }
    }]);
    //用户列表
    directives.directive("userList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/user_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                $scope.searchParam={};
                var getList=function(){
                    xddService.getUserList( $scope.currentPage,$scope.itemsPerPage,$scope.searchParam,function(data){
                        $scope.userList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                getList();
                $scope.searchList=function(){
                    getList();
                }
                $scope.pageChanged=function(){
                    getList();
                };

                $scope.deleteUser=function(user){
                    var userIds=[user.id];
                    //询问框
                    layer.confirm("删除后将无法恢复是否确认删除", {
                        btn: ['确认','取消'] //按钮
                    }, function(){
                        layer.closeAll('dialog');
                        xddService.deleteUser(userIds,function(data){
                            alert("删除成功");
                            getList();
                        },error)

                    }, function(){
                    });
                }
                //审核用户
                $scope.checkUser=function(user){
                    var addGType=$uibModal.open({
                        animation: true,
                        size:"sm",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/check_user.html',
                        controller: "checkUserController",
                        resolve: {
                            model:{}
                        }
                    });
                }
                $scope.checkUser=function(user){
                    $uibModal.open({
                        animation: true,
                        size:"sm",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/check_user.html',
                        controller: "checkUserController",
                        resolve: {
                            model:{user:user}
                        }
                    });
                }
                //分配角色
                $scope.userRoleFP=function(user){
                    $uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/user_role_fp.html',
                        controller: "userRoleFPController",
                        resolve: {
                            model:{user:user}
                        }
                    });
                }


            }
        }
    }]);
    //用户详情
    directives.directive("userDetail", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/user_detail.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.userId=$stateParams.userId;
                xddService.getUserDetail($scope.userId,function(data){
                    $scope.user=data.data;
                },error);

                xddService.getRoleById($scope.userId,function(data){
                    $scope.roleNames=data.data;
                },error);


                $scope.lookYyzz=function(yyzzUrl){
                   $uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/look_yyzz.html',
                        controller: "lookUserYyzzController",
                        resolve: {
                            model:{yyzzUrl:yyzzUrl}
                        }
                    });
                }
                $scope.checkUser=function(user){
                    $uibModal.open({
                        animation: true,
                        size:"sm",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/check_user.html',
                        controller: "checkUserController",
                        resolve: {
                            model:{user:user}
                        }
                    });
                }


            }
        }
    }]);

    //用户编辑
    directives.directive("userUpdate", ['$http','$stateParams','CurrentUser','xddService','$uibModal', function ($http,$stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/user_update.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.userId=$stateParams.userId;
                xddService.getUserDetail($scope.userId,function(data){
                    $scope.user=data.data;
                },error);
                $scope.lookYyzz=function(yyzzUrl){
                    $uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/look_yyzz.html',
                        controller: "lookUserYyzzController",
                        resolve: {
                            model:{yyzzUrl:yyzzUrl}
                        }
                    });
                };


                var uploadFile=function (formData) {
                    $http({
                        method:'POST',
                        url:"/dapi/upload/link",
                        data: formData,
                        headers: {'Content-Type':undefined},
                        transformRequest: angular.identity
                    }).success(function(data){
                        $scope.user.yyzz=data.data;
                        xddService.updateUser($scope.user,function(data){
                            alert("修改成功")
                            xddService.getUserDetail($scope.userId,function(data){
                                $scope.user=data.data;
                            },error);
                        },error);
                    });


                };
                //修改
                $scope.updateUser=function(){
                    var formData = new FormData();
                    if(document.querySelector('input[type="file"]').files[0]!=null){
                        formData.append("file",document.querySelector('input[type="file"]').files[0]);
                        uploadFile(formData);
                    }else{
                        xddService.updateUser($scope.user,function(data){
                            alert("修改成功")
                            xddService.getUserDetail($scope.userId,function(data){
                                $scope.user=data.data;
                            },error);
                        },error);
                    }

                }

            }
        }
    }]);


    //角色列表
    directives.directive("roleList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/role_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                var getRoleListFun=function(){
                    xddService.getRoleList($scope.currentPage, $scope.itemsPerPage,{},function(data){
                        $scope.roleList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error)
                }
                getRoleListFun();
                //删除角色
                $scope.deleteRoleFun=function(role){
                    layer.confirm('确认要删除吗？删除后不可恢复', {
                        btn : [ '确定', '取消' ]//按钮
                    }, function(index) {
                        layer.close(index);
                        xddService.deleteRole(role.code,function(data){
                            alert("删除成功");
                            getRoleListFun();
                        },error)
                    });
                }
                //添加角色
                $scope.addRole=function(){
                    var addRole=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/role_add.html',
                        controller: "roleAddController",
                        resolve: {
                            model:{}
                        }
                    });
                    addRole.result.then(function () {
                        getRoleListFun();
                    });
                }

            }
        }
    }]);
    //角色权限列表
    directives.directive("rolePermList", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/role_perm_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.roleCode=$stateParams.roleCode;
                var getRolePermListFun=function(){
                    xddService.getPermListbyRoleCode($scope.roleCode,function(data){
                        $scope.rolePermList=data.data;
                    },error)
                }
                getRolePermListFun();
                //获取所有权限
                xddService.getAllPermList(function(data){
                    $scope.permList=data.data;
                    $scope.curPerm=data.data[0].code;
                },error)
                //给角色添加权限
                $scope.addPermToRole=function(){
                    xddService.addPermToRole($scope.roleCode,$scope.curPerm,function(data){
                        alert("添加成功");
                        getRolePermListFun();
                    },error)

                }
                //删除角色权限
                $scope.deletePermFromRole=function(code){
                    xddService.deletePermToRole($scope.roleCode,code,function(data){
                        alert("删除成功");
                        getRolePermListFun();
                    },error);
                }

            }
        }
    }]);
    //公告列表
    directives.directive("noticeList", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/notice_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=10;
                $scope.totalItems=0;
                var getNoticeList=function(){
                    //获取协议列表数据
                    xddService.getNoticeList($scope.currentPage, $scope.itemsPerPage,{},function(data){
                        $scope.noticeList=data.data.list;
                        if( $scope.currentPage==1){
                            $scope.totalItems = data.data.count;
                        }
                    },error)
                }
                getNoticeList();
                //启用公告
                $scope.enableNoticeFun=function(noticeId){
                    xddService.enableNotice(noticeId,function(data){
                        getNoticeList();
                    },error)
                }
                $scope.pageChanged=function(){
                    getNoticeList();
                };


            }
        }
    }]);
    //公告详情
    directives.directive("noticeDetail", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/notice_detail.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                //获取公告信息
                xddService.getNoticeById($stateParams.id,function(data){
                    $scope.notice=data.data;
                },error)
                $scope.submitNotice=function(){
                    xddService.updateNotice($scope.notice,function(data){
                        alert("修改成功");
                    },error)
                }
            }
        }
    }]);
    //公告详情
    directives.directive("noticeAdd", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/notice_add.html",
            link: function ($scope) {
                $scope.submitIsClick=false;
                var error=function(err){
                    $scope.submitIsClick=false;
                    layer.alert(err.message);
                }
                $scope.addNotice=function(){
                    $scope.submitIsClick=true;
                    xddService.addNotice($scope.notice,function(data){
                        alert("添加成功");
                        $scope.submitIsClick=false;
                    },error)
                }
            }
        }
    }]);
    //字典列表
    directives.directive("dicList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/dic_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                var getGTypeList=function(){
                    xddService.getGtypeList(function(data){
                        $scope.gtypeList=data.data;
                    },error)
                }
                getGTypeList();

                $scope.enableGtypeFun=function(gtype){
                    xddService.enableGtype(gtype.id,!gtype.ifUse,function(data){
                        getGTypeList();
                    },error)

                }

                $scope.addGTypeFun=function(){
                    var addGType=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/gtype_add_or_update.html',
                        controller: "addGTypeController",
                        resolve: {
                            model:{}
                        }
                    });
                    addGType.result.then(function () {
                        getGTypeList();
                    });
                }
                $scope.updateGTypeFun=function(gtype){
                    var updateGType=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/gtype_add_or_update.html',
                        controller: "updateGTypeController",
                        resolve: {
                            model:{gtype:gtype}
                        }
                    });
                    /*addGType.result.then(function () {
                        getGTypeList();
                    });*/
                }

            }
        }
    }]);

    /**
     * 旧物列表页面
     */
    directives.directive("oldGoodsList", ['$q','$location','$stateParams','CurrentUser','$uibModal','xddService', function ($q,$location,$stateParams,CurrentUser,$uibModal,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/oldGoods_list.html",
            link: function ($scope) {
                $scope.oldParam={};
                $scope.currentPage=1;
                $scope.itemsPerPage=10;
                xddService.getGType('2',function (data) {
                    $scope.typeList=data.data;
                },function () {

                });
                var getList = function () {
                    xddService.getOldList($scope.currentPage, $scope.itemsPerPage, $scope.oldParam, function (data) {
                        $scope.oldGoodsList = data.data.list;
                        if( $scope.currentPage==1){
                            $scope.totalItems = data.data.count;
                        }
                    }, function (data) {
                        alert(data.message);
                    });
                };
                getList();
                $scope.pageChanged=function(){
                    getList();
                };
                $scope.searchOldList=function(){
                    $scope.currentPage=1;
                    getList();
                }

                $scope.deleteOld=function (oldId) {
                    xddService.deleteOld(oldId,function(){
                        alert("删除成功！");
                        getList();
                    },function () {
                        alert("删除失败！");
                    })
                };
                //修改交易状态
                $scope.updateStatus=function(old,status){
                    if(old.status!="1"){
                        alert("尚未审核通过不允许操作");
                        return false;
                    }
                    xddService.updateDealStatus(old.id,status,function(){
                        alert("操作成功");
                        getList();
                    },function () {
                        alert("操作失败，请重试！")
                    });
                };
                //审核旧物
                $scope.checkOld=function (oldId) {
                    var checkOld=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/goodsReview.html',
                        controller: "checkOldController",
                        resolve: {
                            model:{oldId:oldId}
                        }
                    });
                    checkOld.result.then(function () {
                        getList();
                    });
                }

            }
        }
    }]);
    //商品详情
    directives.directive("oldGoodsDetail", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/oldGoods_detail.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                xddService.getGType('2',function (data) {
                    $scope.typeList=data.data;
                },function () {

                });
                xddService.getGStyle(function (data) {
                    $scope.gstyleList=data.data;
                },function () {

                });
                //获取商品信息
                xddService.getOldById($stateParams.id,function(data){
                    $scope.old=data.data;
                },error)
            }
        }
    }]);
    //添加旧物页面
    directives.directive("oldGoodsAdd", ['$stateParams','xddService', function ($stateParams,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: function () {
                return "/app/partial/xdd/oldGoods_add.html";
            },
            link: function ($scope) {
                $scope.picUrl="";
                $("#file-1").fileinput({
                    uploadUrl: "/dapi/upload/attachment", // you must set a valid URL here else you will get an error
                    allowedFileExtensions : ['jpg','jpeg', 'png','gif'],
                    overwriteInitial: false,
                    maxFileSize: 100000,

                    //allowedFileTypes: ['image', 'video', 'flash'],
                    slugCallback: function(filename) {
                       // console.error(filename);
                        return filename.replace('(', '_').replace(']', '_');
                    }
                }) .on("fileuploaded", function(event, data) {
                    if(data.response) {
                        $scope.picUrl=data.response.data;
                        //alert('处理成功');
                    }
                });

                xddService.getGType('2',function (data) {
                    $scope.typeList=data.data;
                },function () {

                });
                $scope.addOld=function () {
                    // if($scope.old.title==null || $scope.old.title==""){
                    //     alert("旧物名不能为空！");
                    //     return;
                    // }else if($scope.old.type==null || $scope.old.type==""){
                    //     alert("含金量不能为空！");
                    //     return;
                    // }else if($scope.old.perWeight==null || $scope.old.perWeight==""){
                    //     alert("重量不能为空！");
                    //     return;
                    // }else if($scope.old.des==null || $scope.old.des==""){
                    //     alert("旧物描述不能为空！");
                    //     return;
                    // }
                    if($scope.picUrl==undefined||$scope.picUrl==""){
                        alert("请上传图片");
                        return false;
                    }
                    $scope.old.ifPic=1;
                    $scope.old.iconUrl=$scope.picUrl;
                    xddService.addOld($scope.old,function () {
                        alert("添加成功")
                        $scope.submitIsClick=false;
                    },function () {

                    });
                }
            }
        }
    }]);
    //估价旧物
    directives.directive("oldAssess", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/old_assess.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.submitAssess=function(){
                    $scope.old.id = $stateParams.id;
                    xddService.assessOld($scope.old,function(data){
                        alert("估价成功");
                    },error)
                }
            }
        }
    }]);

    //订单列表
    directives.directive("orderList", ['$stateParams','Base','CurrentUser','xddService','$uibModal', function ($stateParams,Base,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/order_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.orderParam={};
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                //列表查询
                var getOrderList=function(){
                    $scope.orderParam.ifPC="PC";
                    xddService.getOrderList( $scope.currentPage,$scope.itemsPerPage,$scope.orderParam,function(data){
                        $scope.orderList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                //初始化列表
                getOrderList();
                $scope.pageChanged=function(){
                    getOrderList();
                };

                $scope.searchOrderList=function(){
                    $scope.currentPage=1;
                    getOrderList();
                }

                $scope.updateOrder=function(order){
                    var updateGType=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/order_update.html',
                        controller: "updateOrderController",
                        resolve: {
                            model:{order:order}
                        }
                    });
                }
                $scope.exportOrder=function(orderId){
                    window.location=Base.stringFormat("/{0}/order/export/order/"+orderId, "api");
                }
            }
        }
    }]);
    //订单详情
    directives.directive("orderDetail", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/order_detail.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                //获取订单信息
                xddService.getOrderById($stateParams.id,function(data){
                    $scope.order=data.data;
                },error)
                $scope.updatePhStatus=function (goods) {
                    var phStatus=goods.phStatus;
                    $scope.good=goods;
                    if(phStatus==1){
                        $scope.good.phStatus=0;
                        xddService.updatePhStatus(goods,function () {
                            alert("修改成功");
                        },error)
                    }else if(phStatus==0){
                        $scope.good.phStatus=1;
                        xddService.updatePhStatus(goods,function () {
                            alert("修改成功");
                        },error)
                    }
                }
                xddService.getGoogsTypeList(function(data){
                    $scope.gTypeList=data.data;
                },error);
                $scope.getTypeIfContain=function(id,ids){
                    var flag=false;
                    for(var i=0;i<ids.length;i++){
                        if(id==ids[i]){
                            flag=true;
                            return flag;
                        }
                    }
                    return flag;
                }
                $scope.typeOneClick=function(item){
                    $scope.typeOneChecked=item.id;//一级选中
                    $scope.typeChecked="";//二级选中
                    $scope.typeList=item.typeList;
                    $scope.curTypeOne=item;
                    $scope.curType={};
                }

                $scope.typeClick=function(item){
                    $scope.typeChecked=item.id;
                    $scope.curType=item;
                    $scope.curTypeOne={};
                }
            }
        }
    }]);
    //订单信息修改
    directives.directive("orderUpdate", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/order_detail.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                };
                //获取订单信息
                xddService.getOrderById($stateParams.id,function(data){
                    $scope.order=data.data;
                },error)
            }
        }
    }]);
    //估价旧物
    directives.directive("orderCourier", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/order_courier.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.order={};
                $scope.submitExpressCode=function(){
                    $scope.order.orderId = $stateParams.orderId;
                    xddService.addExpressCode($scope.order,function(data){
                        alert("添加物流信息成功");
                    },error)
                }
            }
        }
    }]);
    //优惠券详情
    directives.directive("couponShare", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/coupon_share.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.type=$stateParams.type;


            }
        }
    }]);
    //优惠券列表
    directives.directive("couponList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/coupon_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=15;
                $scope.totalItems=0;
                $scope.param={};
                $scope.param.ifCanUse=true;
                var getList=function(){
                    xddService.getCouponList( $scope.currentPage,$scope.itemsPerPage, $scope.param,function(data){
                        $scope.couponList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                getList();
                $scope.pageChanged=function(){
                    getList();
                };
                $scope.paramSearch=function(){
                    getList();
                }
                $scope.addCoupon=function(){
                    var addCoupon=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/coupon_add.html',
                        controller: "addCouponController",
                        resolve: {
                            model:{}
                        }
                    });
                    addCoupon.result.then(function () {
                        getList();
                    });
                }
            }
        }
    }]);
    //优惠券设置
    directives.directive("couponSetting", ['$stateParams','CurrentUser','xddService', function ($stateParams,CurrentUser,xddService) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/coupon_setting.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.couponId=$stateParams.couponId;
                //获取优惠券
                xddService.getCouponById($scope.couponId,function(data){
                    $scope.coupon=data.data;
                },error);
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                $scope.searchParam={checkStatus:'1'};
                var getList=function(){
                    xddService.getUserList( $scope.currentPage,$scope.itemsPerPage,$scope.searchParam,function(data){
                        $scope.userList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                getList();
                $scope.searchList=function(){
                    getList();
                }
                $scope.pageChanged=function(){
                    getList();
                };
                $scope.sendBtn=false;
                function getCheckBoxRes(name){
                    var rdsObj   = document.getElementsByName(name);
                    var checkVal = new Array();
                    var k        = 0;
                    for(var i = 0; i < rdsObj.length; i++){
                        if(rdsObj[i].checked){
                            checkVal[k] = rdsObj[i].value;
                            k++;
                        }
                    }
                    return checkVal;
                }
                $scope.number=1;
                $scope.submitCouponUser=function(){
                    $scope.sendBtn=true;
                   var userIds= getCheckBoxRes("userId");
                    var sendCouponUser={}
                    sendCouponUser.userIds=userIds;
                    sendCouponUser.couponId= $scope.couponId;
                    sendCouponUser.number=$scope.number;
                    if(userIds.length<=0){
                        alert("请选择要发放用户");
                        return false;
                    }
                    if($scope.number==undefined||$scope.number<0){
                        alert("请输入数量");
                        return false;
                    }
                    xddService.sendCouponToUser(sendCouponUser,function(data){
                        alert("发放成功");
                        $scope.sendBtn=false;
                    },error)


                }

                $scope.numberInput=function(){
                    $("#numberInput").val($("#numberInput").val().replace(/[^\-?\d.]/g,''));
                }

            }
        }
    }]);
    //单价维护页面
    directives.directive("goodsPrice", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/goods_price.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
               /* xddService.getGType('1',function (data) {
                    $scope.typeList=data.data;
                },error);*/
                xddService.getGTypeOneTwoList(function(data){
                    $scope.typeList=data.data;
                },error);
                $scope.updatePrice=function(gtype){
                    xddService.updatePrice(gtype,function(data){
                        alert("更新成功");
                    },error)
                }

                $scope.showTypeClick=function(gtypeId){
                    $scope.showId=gtypeId;
                }
            }
        }
    }]);
    //统计分析
    directives.directive("analyAll", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/common_tjfx.html",
            link: function ($scope) {
                $scope.type=$stateParams.type;
            }
        }
    }]);
    //商品类型统计分析
    directives.directive("tjfxGstylePage", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/gStyle_tjfx.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.anParam={};
                var getAnalysis=function(){
                    xddService.analysisByGStyle( $scope.anParam,function (data) {
                        $scope.anayAll=data.data;
                        $scope.anayList=data.data.list;
                        var sumWeight=0;

                        angular.forEach($scope.anayList, function (data) {
                            sumWeight+=data.dealWeight;
                        });
                        $scope.sumWeight=sumWeight;
                        var xsNums = new Array();
                        var xsDealWeight = new Array();
                        var xsStyleName = new Array();
                        angular.forEach($scope.anayList, function (data) {
                            xsNums.push(data.dealNum);
                            xsDealWeight.push(data.dealWeight);
                            xsStyleName.push(data.styleName);
                        });
                        var domOne = document.getElementById("analysis_container");
                        var myChartOne = require('echarts').init(domOne);
                        var app = {};
                        var optionOne = null;
                        app.title = '坐标轴刻度与标签对齐';

                        optionOne = {
                            title: {
                                subtext: '销售量/件',
                                //副标题文本样式
                                subtextStyle: {}
                            },
                            color: ['#3398DB'],
                            tooltip : {
                                trigger: 'axis',
                                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis : [
                                {
                                    type : 'category',
                                    data : xsStyleName,
                                    axisTick: {
                                        alignWithLabel: true
                                    }
                                }
                            ],
                            yAxis : [
                                {
                                    type : 'value'
                                }
                            ],
                            series : [
                                {
                                    name:'销售量',
                                    type:'bar',
                                    barWidth: '60%',
                                    data:xsNums,
                                    itemStyle: {
                                        //通常情况下：
                                        normal: {　　　　　　　　　　　　 //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                                            color: function(params) {
                                                var colorList = ['#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C','#ff9f7f', '#fb7293'];
                                                return colorList[params.dataIndex];
                                            }
                                        },
                                        //鼠标悬停时：
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    },
                                }
                            ]
                        };
                        ;
                        if (optionOne && typeof optionOne === "object") {
                            myChartOne.setOption(optionOne, true);
                        }
                        var dom = document.getElementById("analysis_container2");
                        var myChart = require('echarts').init(dom);
                        var app = {};
                        var option = null;
                        app.title = '坐标轴刻度与标签对齐';

                        option = {
                            title: {
                                subtext: '销售量/g',
                                //副标题文本样式
                                subtextStyle: {}
                            },
                            color: ['#3398DB'],
                            tooltip : {
                                trigger: 'axis',
                                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis : [
                                {
                                    type : 'category',
                                    data : xsStyleName,
                                    axisTick: {
                                        alignWithLabel: true
                                    }
                                }
                            ],
                            yAxis : [
                                {
                                    type : 'value'
                                }
                            ],
                            series : [
                                {
                                    name:'销售量',
                                    type:'bar',
                                    barWidth: '60%',
                                    data:xsDealWeight,
                                    itemStyle: {
                                        //通常情况下：
                                        normal: {　　　　　　　　　　　　 //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                                            color: function(params) {
                                                var colorList = ['#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C','#ff9f7f', '#fb7293'];
                                                return colorList[params.dataIndex];
                                            }
                                        },
                                        //鼠标悬停时：
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    },
                                }
                            ]
                        };
                        ;
                        if (option && typeof option === "object") {
                            myChart.setOption(option, true);
                        }
                    },error);
                }
                getAnalysis();
                $scope.searchAnalysis=function(){
                    getAnalysis();
                }
            }
        }
    }]);
    //商品材质统计分析
    directives.directive("tjfxGtypePage", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/gType_tjfx.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.anParam={};
                var getAnalysis=function(){
                    xddService.analysisByType( $scope.anParam,function (data) {
                        $scope.anayAll=data.data;
                        $scope.anayList=data.data.list;
                        var xsNums = new Array();
                        var xsMoney = new Array();
                        var xsTypeName = new Array();
                        angular.forEach($scope.anayList, function (data) {
                            xsNums.push(data.dealNum);
                            xsMoney.push(data.dealPrice);
                            xsTypeName.push(data.typeName);

                        });
                        //统计图表
                        var domOne = document.getElementById("analysis_container");
                        var myChartOne = require('echarts').init(domOne);
                        var app = {};
                        var optionOne = null;
                        app.title = '坐标轴刻度与标签对齐';

                        optionOne = {
                            title: {
                                subtext: '销售量/件',
                                //副标题文本样式
                                subtextStyle: {}
                            },
                            color: ['#3398DB'],
                            tooltip : {
                                trigger: 'axis',
                                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis : [
                                {
                                    type : 'category',
                                    data : xsTypeName,
                                    axisTick: {
                                        alignWithLabel: true
                                    }
                                }
                            ],
                            yAxis : [
                                {
                                    type : 'value'
                                }
                            ],
                            series : [
                                {
                                    name:'销售量',
                                    type:'bar',
                                    barWidth: '30%',
                                    data:xsNums,
                                    itemStyle: {
                                        //通常情况下：
                                        normal: {　　　　　　　　　　　　 //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                                            color: function(params) {
                                                var colorList = ['#37A2DA','#fb7293'];
                                                return colorList[params.dataIndex];
                                            }
                                        },
                                        //鼠标悬停时：
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    },
                                }
                            ]
                        };
                        ;
                        if (optionOne && typeof optionOne === "object") {
                            myChartOne.setOption(optionOne, true);
                        }
                        var dom = document.getElementById("analysis_container2");
                        var myChart =require('echarts').init(dom);
                        var app = {};
                        var option = null;
                        app.title = '坐标轴刻度与标签对齐';

                        option = {
                            title: {
                                subtext: '销售额/万元',
                                //副标题文本样式
                                subtextStyle: {}
                            },
                            color: ['#3398DB'],
                            tooltip : {
                                trigger: 'axis',
                                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis : [
                                {
                                    type : 'category',
                                    data : xsTypeName,
                                    axisTick: {
                                        alignWithLabel: true
                                    }
                                }
                            ],
                            yAxis : [
                                {
                                    type : 'value'
                                }
                            ],
                            series : [
                                {
                                    name:'销售额',
                                    type:'bar',
                                    barWidth: '30%',
                                    data:xsMoney,
                                    itemStyle: {
                                        //通常情况下：
                                        normal: {　　　　　　　　　　　　 //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                                            color: function(params) {
                                                var colorList = ['#37A2DA', '#fb7293'];
                                                return colorList[params.dataIndex];
                                            }
                                        },
                                        //鼠标悬停时：
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    },
                                }
                            ]
                        };
                        ;
                        if (option && typeof option === "object") {
                            myChart.setOption(option, true);
                        }
                    },error);
                }
                getAnalysis();
                $scope.searchAnalysis=function(){
                    getAnalysis();
                }
            }
        }
    }]);
    //分享
    directives.directive("translateList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/translate_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                $scope.currentPage=1;
                $scope.itemsPerPage=20;
                $scope.totalItems=0;
                //列表查询
                var getTranslateList=function(){
                    xddService.getTranslateList( $scope.currentPage,$scope.itemsPerPage,function(data){
                        $scope.translateList=data.data.list;
                        if($scope.currentPage==1){
                            $scope.totalItems=data.data.count;
                        }
                    },error);
                }
                //初始化列表
                getTranslateList();
                $scope.pageChanged=function(){
                    getTranslateList();
                };

            }
        }
    }]);
    //代理商列表
    directives.directive("agentList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/agent_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                var getList=function(){
                    xddService.getAgentList(function(data){
                        $scope.agentList=data.data;
                    },error)
                }
                getList();
                $scope.deleteAgentFun=function(agentId){
                    xddService.deleteAgentById(agentId,function(data){
                        getList();
                    },error)
                }
                $scope.addAgentFun=function(){
                    var addAgent=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/agent_add_update.html',
                        controller: "addAgentController",
                        resolve: {
                            model:{}
                        }
                    });
                    addAgent.result.then(function () {
                        getList();
                    });
                }
                $scope.updateAgentFun=function(agent){
                    var updateAgent=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/agent_add_update.html',
                        controller: "updateAgentController",
                        resolve: {
                            model:{agent:agent}
                        }
                    });
                }
            }
        }
    }]);
    //商品一级属性维护--列表
    directives.directive("typeoneList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/typeOne_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                var getList=function(){
                    xddService.getGTypeOneList(function(data){
                        $scope.typeOneList=data.data;
                    },error)
                }
                getList();
                $scope.secondID="";
                $scope.thirdID="";
                $scope.fourthID="";
                $scope.openSecond=function(id){
                    $scope.secondID=id;
                }
                $scope.openThird=function(id){
                    $scope.thirdID=id;
                }
                $scope.openFourth=function(id){
                    $scope.fourthID=id;
                }
                $scope.deleteTypeOne=function(id){
                    xddService.deleteTypeOneById(id,function(data){
                        getList();
                    },error)
                }
                $scope.enableGtypeFun=function(gtype){
                    xddService.enableGtype(gtype.id,!gtype.ifUse,function(data){
                        getList();
                    },error)

                }
                $scope.deleteGStyle=function(id){
                    xddService.deleteGStyleById(id,function(data){
                        getList();
                    },error)
                }
                $scope.deletePX=function(id){
                    xddService.deletePX(id,function(data){
                        getList();
                    },error)
                }
                $scope.addTypeOne=function(){
                    var addTypeOne=$uibModal.open({//添加一级
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/typeOne_add_update.html',
                        controller: "addTypeOneController",
                        resolve: {
                            model:{}
                        }
                    });
                    addTypeOne.result.then(function () {
                        getList();
                    });
                }
                $scope.updateTypeOne=function(type){//修改一级
                    var updateAgent=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/typeOne_add_update.html',
                        controller: "updateTypeOneController",
                        resolve: {
                            model:{type:type}
                        }
                    });
                }
                $scope.addGTypeFun=function(pId){//添加二级----材质
                    var addGType=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/gtype_add_or_update.html',
                        controller: "addGTypeController",
                        resolve: {
                            model:{pId:pId}
                        }
                    });
                    addGType.result.then(function () {
                        getList();
                    });
                }
                $scope.updateGTypeFun=function(gtype){//修改二级----材质
                    var updateGType=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/gtype_add_or_update.html',
                        controller: "updateGTypeController",
                        resolve: {
                            model:{gtype:gtype}
                        }
                    });

                }
                $scope.addGStyle=function(pId){//添加三级----样式
                    var addGStyle=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/gstyle_add_or_update.html',
                        controller: "addGStyleController",
                        resolve: {
                            model:{pId:pId}
                        }
                    });
                    addGStyle.result.then(function () {
                        getList();
                    });
                }
                $scope.updateGStyle=function(gstyle){//修改三级----样式
                    var updateGStyle=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/gstyle_add_or_update.html',
                        controller: "updateGStyleController",
                        resolve: {
                            model:{gstyle:gstyle}
                        }
                    });
                }
                $scope.addPinX=function(pId){//添加四级---品型
                    var addPX=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/pinxing_add_or_update.html',
                        controller: "addPXController",
                        resolve: {
                            model:{pId:pId}
                        }
                    });
                    addPX.result.then(function () {
                        getList();
                    });
                }
                $scope.updatePX=function(px){//修改四级----品型
                    var updateGStyle=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/pinxing_add_or_update.html',
                        controller: "updatePXController",
                        resolve: {
                            model:{px:px}
                        }
                    });
                }
                /*var getListById=function(pid,level){
                    xddService.getSecondType(pid,level,function(data){
                        if(level=="1"){
                            $scope.typeList=data.data.typeList;
                        }else{
                            $scope.styleList=data.data.styleList;
                        }
                    },error)
                }*/
            }
        }
    }]);
    //APP首页轮播图片列表
    directives.directive("appPicList", ['$stateParams','CurrentUser','xddService','$uibModal', function ($stateParams,CurrentUser,xddService,$uibModal) {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl: "/app/partial/xdd/appPic_list.html",
            link: function ($scope) {
                var error=function(err){
                    layer.alert(err.message);
                }
                var getList=function(){
                    xddService.getAppPicList(function(data){
                        $scope.appPicList=data.data;
                    },error)
                }
                getList();
                $scope.deleteAppPic=function(appPicId){
                    xddService.deleteAppPicById(appPicId,function(data){
                        getList();
                    },error)
                }
                $scope.addAppPic=function(){
                    var addAppPic=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/appPic_add_update.html',
                        controller: "addAppPicController",
                        resolve: {
                            model:{}
                        }
                    });
                    addAppPic.result.then(function () {
                        getList();
                    });
                }
                $scope.updateAppPic=function(appPic){
                    var updateAppPic=$uibModal.open({
                        animation: true,
                        size:"lg",
                        backdrop:'static',
                        templateUrl: '/app/partial/xdd/appPic_add_update.html',
                        controller: "updateAppPicController",
                        resolve: {
                            model:{appPic:appPic}
                        }
                    });
                    updateAppPic.result.then(function () {
                        getList();
                    });
                }
            }
        }
    }]);
});